﻿using Microsoft.Practices.EnterpriseLibrary.Security;
using Microsoft.Practices.EnterpriseLibrary.Security.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using System.Data;
using System.Collections.Specialized;

namespace Nortec.Security
{
    [ConfigurationElementType(typeof(CustomAuthorizationProviderData))]
    public class NortecAuthorizationProvider : AuthorizationProvider
    {
        public NortecAuthorizationProvider(NameValueCollection configurationItems) { }

        public override bool Authorize(System.Security.Principal.IPrincipal principal, string context)
        {
            var p = (NortecPrincipal)principal;
            DataRow[] rights = p.AccessRights.Select("lit_privilegio_nombre = '" + context + "'");

            return (rights.Length > 0);
        }
    }
}
